<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">单击有惊喜！！！</button>
    <script>
        //步骤1：获取事件源
        var btn = document.getElementById('btn');
        //步骤2：注册事件btn.onclick
        btn.onclick = function(){ 
        //步骤3：添加事件处理程序（采取函数赋值的方式）
            alert('你上当了！！！');
        }
    </script>
</body>
</html>